﻿using Updater.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml;
using System;

namespace Updater.Service.UnitTest
{
    
    
    /// <summary>
    ///This is a test class for SiteInfoTest and is intended
    ///to contain all SiteInfoTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SiteInfoTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:                
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        #region Methods run before/after tests
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //    Downloader.CopySettings();
        //}

        ////Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //    Downloader.RestoreSettings();
        //}

        ////Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //    Downloader.SetTestSettings();
        //}

        #endregion

        /// <summary>
        ///A test for IsTimeToInstall
        ///</summary>
        [TestMethod()]
        public void IsTimeToInstallTest()
        {
            Downloader_Accessor testDownloader = new Downloader_Accessor();
            DateTime date = new DateTime(2000, 1, 2, 9, 0, 0);

            Assert.IsFalse( testDownloader.siteInfos[2].IsTimeToInstall(date),"Hour test == false failed.");
            date = new DateTime(2000, 1, 2, 1, 0, 0);
            Assert.IsTrue(testDownloader.siteInfos[2].IsTimeToInstall(date), "Hour test == true failed.");

            date = new DateTime(2000, 1, 7, 1, 0, 0);
            for (int i = 0; i < 7; i++)
            {
                date = date.AddDays(1);
                DayOfWeek testDay = date.DayOfWeek;
                Assert.AreEqual(date.DayOfWeek == DayOfWeek.Monday, testDownloader.siteInfos[3].IsTimeToInstall(date),"DayOfWeek test failed.");
            }
            date = new DateTime(2000, 1, 16, 1, 0, 0);
            Assert.IsTrue(testDownloader.siteInfos[3].IsTimeToInstall(date), "DayOfWeek 2 weeks test failed.");

            date = new DateTime(2000, 1, 19, 1, 0, 0);
            Assert.IsFalse(testDownloader.siteInfos[4].IsTimeToInstall(date), "Month test(1) == false failed.");
            date = new DateTime(2000, 1, 1, 1, 0, 0);
            Assert.IsFalse(testDownloader.siteInfos[4].IsTimeToInstall(date), "Month test(2) == false failed.");
            date = new DateTime(2000, 2, 1, 1, 0, 0);
            Assert.IsTrue(testDownloader.siteInfos[4].IsTimeToInstall(date), "Month test(1) == true failed.");
            date = new DateTime(2000, 3, 19, 1, 0, 0);
            Assert.IsTrue(testDownloader.siteInfos[4].IsTimeToInstall(date), "Month test(2) == true failed.");

            date = new DateTime(2000, 12, 19, 1, 0, 0);
            Assert.IsFalse(testDownloader.siteInfos[5].IsTimeToInstall(date), "Year test == false failed.");
            date = new DateTime(2001, 1, 1, 1, 0, 0);
            Assert.IsTrue(testDownloader.siteInfos[5].IsTimeToInstall(date), "Year test(1) == true failed.");
            date = new DateTime(2001, 2, 19, 1, 0, 0);
            Assert.IsTrue(testDownloader.siteInfos[4].IsTimeToInstall(date), "Year test(2) == true failed.");
        }
    }
}
